package com.xb.system.redis;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.time.Duration;

/**
 * Rediskey 的管理类
 * 约定：redis 每个key 都跟枚举类实例一一对应
 */
@Getter
public enum RedisKeys {

    // 在线人数 online number
    ONLINE_NUMBER("online_number", Duration.ofHours(24));


    private Duration ttl;      //redis key 的有效时间，单位s
    private String prefix;  //redis key 前缀

    private RedisKeys(String prefix, Duration ttl){
        this.ttl = ttl;
        this.prefix = prefix;
    }
    //拼接出真实key
    public String join(String... values){
        StringBuilder sb = new StringBuilder(80);
        sb.append(this.prefix);
        for (String value : values) {
            sb.append(":").append(value);
        }
        return sb.toString();
    }

}
